﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using Microsoft.Practices.Web.UI.WebControls;
using Ornament.MemberShip;
using Ornament.MemberShip.Module.Presenters;
using Ornament.MemberShip.Module.Views;

public partial class Admin_MemberAdmin_Controls_UserListCtl : UserControl, IUserBrowserView
{
    #region IUserBrowserView Members

    /// <summary>
    /// 
    /// </summary>
    public int PageSize
    {
        get { return ListView1.PageSize; }
    }

    /// <summary>
    /// 
    /// </summary>
    public bool IsLockOut
    {
        get { return true; // IsLockCheckBox.Checked; 
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public bool IsApproved
    {
        get { return true; //IsApprovedCheckBox.Checked; 
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="result"></param>
    /// <param name="total"></param>
    public void BindSearchResult(IList<User> result, int total)
    {
        ObjectContainerDataSource1.DataSource = result;
        ObjectContainerDataSource1.TotalRowCount = total;
        ObjectContainerDataSource1.DataBind();
    }

    /// <summary>
    /// 
    /// </summary>
    public UserBrowserPresenter Presenter { get; set; }

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        Presenter = new UserBrowserPresenter(this);
        if (!IsPostBack)
        {
            Presenter.InitilizeView();
        }
        Presenter.ViewLoad();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GetUsers(object sender, ObjectContainerDataSourceSelectingEventArgs e)
    {
        if (SearchTextBox.Text.Length != 0)
        {
            switch (dropDownlistSearchType.SelectedValue)
            {
                case "loginid":
                    Presenter.Search(0, SearchTextBox.Text, null, "");
                    break;
                case "e-mail":
                    Presenter.Search(0, null, SearchTextBox.Text, "");
                    break;
                default:
                    Presenter.Search(0, null, null, SearchTextBox.Text);
                    break;
            }
        }
        else
        {
            Presenter.Search(0, null, null, "");
        }
    }

    protected void search(object sender, ImageClickEventArgs e)
    {
        ListView1.DataBind();
    }
}